package com.syx.rabbitmq.orderserver.Controller;

import com.syx.rabbitmq.orderserver.Constant.Constant;
import com.syx.rabbitmq.orderserver.Model.OrderInfo;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RequestMapping("/order")
@RestController
public class OrderController {


    @Resource
    RabbitTemplate rabbitTemplate;



    @RequestMapping("/create")
    public String create(){

        String orderId= UUID.randomUUID().toString();
        rabbitTemplate.convertAndSend("", Constant.ORDER_QUEUE,"订单信息 Id:"+orderId);
        return "下单成功";



    }
    @RequestMapping("/create2")
    public String create2(){
        String orderId1 = UUID.randomUUID().toString();
        OrderInfo orderInfo=new OrderInfo();
        orderInfo.setOrderId(orderId1);
        orderInfo.setName("java开发手册");
        rabbitTemplate.convertAndSend("", Constant.ORDER_QUEUE,orderInfo);
        return "下单成功";



    }






}
